package com.example.democode01.kotlin

fun main() {
   println(ifFunc(100, 200))
   println(whereFunc1(2))
   println(whereFunc2(85))
   
   // 调用三个for循环函数
   println("升序循环（1到10）:")
   ascendingLoop()
   
   println("降序循环（10到1）:")
   descendingLoop()
   
   println("步长为2的循环（1,3,5,7,9）:")
   stepLoop()
}

// 1. if语句
fun ifFunc(num1: Int, num2: Int): Int {
    // 写法1:
    if(num1 > num2){
        return num1
    } else {
        return num2
    }

    // 写法2:
    // if (num1 > num2) println(num1) else println(num2)
}

fun whereFunc1(num1: Int): String{
   val res = when(num1){
      1 -> "one"
      2 -> "two"
      3 -> "three"
      else -> "other"
   }
   return res
}

fun whereFunc2(score: Int): String = when(score){
    in 90..100 -> "A"
    in 80 until 90 -> "B"
    in 70 until 80 -> "C"
    in 60 until 70 -> "D"
    else -> "F"
}

// 升序循环：从1到10
fun ascendingLoop() {
    for (i in 1..10) {
        print("$i ")
    }
    println()
}

// 降序循环：从10到1
fun descendingLoop() {
    for (i in 10 downTo 1) {
        print("$i ")
    }
    println()
}

// 步长为2的循环：从1到10，步长为2
fun stepLoop() {
    for (i in 1..10 step 2) {
        print("$i ")
    }
    println()
}